package com.yunxi.controller.vip;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.vip.pojo.VipVO;
import com.yunxi.vip.service.VipDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2019-09-06
 */
@RestController
@RequestMapping("/admin/vip")
@Api(tags = "pms:vip", description = "接口")
public class VipController {
 private static final Logger logger = LoggerFactory.getLogger(VipController.class);


 @Autowired
 VipDubboService vipDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(VipVO vipVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
     if(StringUtils.isNotEmpty(loginInfo.getPartnerCode())){
         vipVO.setPartnerCode(loginInfo.getPartnerCode());
     }
  return ResponseUtil.ok(vipDubboService.findPageByVO(vipVO,pageNum,pageSize));
 }

@GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(VipVO vipVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        if(StringUtils.isNotEmpty(loginInfo.getPartnerCode())){
            vipVO.setPartnerCode(loginInfo.getPartnerCode());
        }else{
            vipVO.setPartnerCodeNot("true");
        }
      return ResponseUtil.ok(vipDubboService.listByVo(vipVO));
   }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(VipVO vipVO, @CurrentUser LoginInfo loginInfo) throws Exception {
 return ResponseUtil.ok(vipDubboService.getById(vipVO.getVipId()));
}

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody VipVO vipVO,@CurrentUser LoginInfo loginInfo) throws Exception {
  return vipDubboService.saveOrUpdate(vipVO,loginInfo);
}

 @PostMapping("/del")
 @ApiOperation(value = "删除")
 public ApiResult del(@RequestBody List<VipVO> vipVOList) throws Exception {
    vipDubboService.removeByListVo(vipVOList);
 return ResponseUtil.ok("success");
 }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(vipDubboService.findMapByList(params));
}*/
}
